package com.study.lambda;

import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;

public class LambdaTest {

    public static int calculateNum(IntBinaryOperator operator){
        int a = 10;
        int b = 20;
        return operator.applyAsInt(a, b);
    }


    public static void main(String[] args) {

        // 练习一
        System.out.println("============>>> 练习1");
        // 选中 IntBinaryOperator，alt + 回车，IDEA会提示转换成lambda表达式
        int i = calculateNum(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left + right;
            }
        });
        System.out.println(i);

        // lambda 表达式
        int c = calculateNum((int left, int right) -> {
            return left + right;
        });


        // 练习二
        System.out.println("============>>> 练习2");
        printNum(value -> value % 2 == 0);


    }

    public static void printNum(IntPredicate intPredicate){

        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr){
            if(intPredicate.test(i)){
                System.out.println(i);
            }
        }


    }


}
